package karaokestrong.servlets;

import java.io.IOException;
import java.sql.Timestamp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaokestrong.excepcion.DAOExcepcion;
import karaokestrong.modelo.Evento;
import karaokestrong.negocio.GestionEventos;

/**
 * Servlet implementation class ServletEvento
 */
@WebServlet("/ServletEvento")
public class ServletEvento extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletEvento() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
		// TODO Auto-generated method stub
		GestionEventos eventosservlet = new GestionEventos();
		
		try{
		Evento evento = new Evento();
				
		evento.setIdevento(Integer.parseInt(request.getParameter("idlocal")));
		evento.setNombre(request.getParameter("nombre"));
		evento.setFecha(Timestamp.valueOf(request.getParameter("fecha")));
		evento.setCapacidad(Integer.parseInt(request.getParameter("capacidad")));
		evento.setDescripcion(request.getParameter("descripcion"));
		evento.setElog(Boolean.parseBoolean(request.getParameter("false")));
		evento.setIdlocal(Integer.parseInt(request.getParameter("idlocal")));
		
		
		
		eventosservlet.insertar(evento);	
		request.getRequestDispatcher("mensaje.jsp").forward(request, response);
		
		} catch (DAOExcepcion e) {
			System.out.println("Fallo la insercion: " + e.getMessage());
		}
	
	
	}

}
